
import * as signalR from "@microsoft/signalr"

const connection = new signalR.HubConnectionBuilder()
	.withUrl(import.meta.env.VITE_API_URL + "/hubs/onlineUser")
	.build();

connection.start().then(function () {
	console.log('启动了')
}).catch(function (err) {
    return console.error(err.toString());
});

// connection.on("2", function (message) {
// 	console.log(message);
// });
connection.on('ReceiveMessage', function (message) {
	console.log(message);
})

function send() {
	let message = {
		userId: 1,
		title: '测试标题',
		messageType: 0,
		message: '这是一段测试消息'
	}
	// connection.invoke("SendMessage", JSON.stringify(message)).catch(function (err) {
  //     return console.error(err.toString());
  // });

  connection.invoke("SendMessage", '5', '测试发送').catch(function (err) {
      return console.error(err.toString());
  });
}